import Opt from '@/components/dt/info/Opt.js'
import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
import protectOption from '@/biz/protectOption/protectOption'
import dateOpt from '@/biz/option/date.js'
import CustomerMgr from '@/biz/customer/customerOpt.js'
let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '序号',
        minWidth: 60,
        type: 'index',
        align: 'center'
      },
      {
        field: 'customerTypeName',
        minWidth: 170,
        header: {
          filter: {
            title: '类型',
            key: 'customerType',
            placeholder: '请选择类型',
            select: {
              options: [
                { key: '1', value: '线索客户' },
                { key: '2', value: '到访客户' }
              ]
            }
          }
        }
      },
      {
        field: 'customerName',
        title: '客户姓名',
        minWidth: 200,
        header: {
          filter: {
            title: '客户姓名',
            key: 'customerName',
            placeholder: '请输入客户姓名',
            input: {}
          }
        }
      },
      {
        field: 'customerPhone',
        minWidth: 130,
        header: {
          filter: {
            title: '手机号码',
            key: 'customerPhone',
            placeholder: '请输入手机号码',
            input: {}
          }
        }
      },
      {
        field: 'oldUserName',
        minWidth: 170,
        header: {
          filter: {
            title: '原归属顾问',
            key: 'oldUserId',
            placeholder: '请选择归属顾问',
            load: (o) => {
              o.select.options = clueCustomerMgr.selectTeamUser()
            },
            select: {
              options: [],
              multiple: true,
              filterable: true,
              remote: (key) => {
                return clueCustomerMgr.selectTeamUser()
              }
            }
          }
        },
        slots: {
          default: (params, h) => {
            return [h('div', `${params.row.oldUserName}(${params.row.oldUserWorkNumber})`)]
          }
        }
      },
      {
        field: 'customerStatusName',
        minWidth: 120,
        header: {
          filter: {
            title: '客户进度',
            key: 'customerStatus',
            placeholder: '请选择客户进度',
            load: (o) => {
              protectOption.getTypeData({ queryType: 1 }).then((res) => {
                if (res?.length > 0) {
                  o.select.options = res
                    .filter((item) => {
                      return (
                        item.optionKey != 'CAPITAL_VERIFICATION' &&
                        item.optionKey != 'PLEDGED' &&
                        item.optionKey != 'INTENTION_MONEY'
                      )
                    })
                    .map((ele) => {
                      return {
                        key: ele.optionId,
                        value: ele.optionValue
                      }
                    })
                } else {
                  o.select.options = []
                }
              })
            },
            select: {
              options: [],
              multiple: true,
              filterable: true
            }
          }
        }
      },
      {
        field: 'intentionLevelName',
        minWidth: 120,
        header: {
          filter: {
            title: '意向等级',
            key: 'intentionLevel',
            placeholder: '请选择意向等级',
            load: (o) => {
              protectOption.getTypeData({ queryType: 2 }).then((res) => {
                console.log(111, res)
                if (res?.length > 0) {
                  o.select.options = res.map((ele) => {
                    return {
                      key: ele.optionId,
                      value: ele.optionValue
                    }
                  })
                } else {
                  o.select.options = []
                }
              })
            },
            select: {
              options: [],
              multiple: true,
              filterable: true
            }
          }
        }
      },
      {
        field: 'joinPoolReasonName',
        minWidth: 120,
        header: {
          filter: {
            title: '进池原因',
            key: 'joinPoolReason',
            placeholder: '请选择进池原因',
            select: {
              options: [
                {
                  key: 1,
                  value: '无效'
                },
                {
                  key: 2,
                  value: '离案'
                },
                {
                  key: 3,
                  value: '过期'
                }
              ],
              multiple: false,
              filterable: true
            }
          }
        }
      },
      {
        title: '入池时间',
        field: 'joinPoolDate',
        minWidth: 180,
        header: {
          filter: dateOpt.range({
            title: '入池时间',
            placeholder: '请选择入池时间',
            startKey: 'joinPoolDateStart',
            endKey: 'joinPoolDateEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.joinPoolDateStart, val.joinPoolDateEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.joinPoolDateStart, val.joinPoolDateEnd).Y >= 2)
            }
          })
        }
      }
      // {
      //   field: 'snatchingUserName',
      //   minWidth: 170,
      //   header: {
      //     filter: {
      //       title: '抢客人',
      //       key: 'snatchingUserId',
      //       placeholder: '请选择抢客人',
      //       load: (o) => {
      //         o.select.options = clueCustomerMgr.selectTeamUser()
      //       },
      //       select: {
      //         options: [],
      //         // multiple: true,
      //         filterable: true,
      //         remote: (key) => {
      //           return clueCustomerMgr.selectTeamUser()
      //         }
      //       }
      //     }
      //   }
      // },
      // {
      //   title: '抢客时间',
      //   field: 'snatchingDate',
      //   minWidth: 180,
      //   header: {
      //     filter: dateOpt.range({
      //       title: '抢客时间',
      //       placeholder: '请选择抢客时间',
      //       startKey: 'snatchingDateStart',
      //       endKey: 'snatchingDateEnd',
      //       disabled: (date) => {
      //         return date.valueOf() > new Date().getTime()
      //       },
      //       check: (val) => {
      //         if (_this.$tool.dateDiff(val.snatchingDateStart, val.snatchingDateEnd).Y >= 2) {
      //           // 日期最大跨度两年
      //           _this.$Message.warning('日期跨度至多两年。')
      //         }
      //         return !(_this.$tool.dateDiff(val.snatchingDateStart, val.snatchingDateEnd).Y >= 2)
      //       }
      //     })
      //   }
      // },
      // {
      //   field: 'hasFollowedName',
      //   minWidth: 120,
      //   header: {
      //     filter: {
      //       title: '是否跟进',
      //       key: 'hasFollowed',
      //       placeholder: '请选择是否跟进',
      //       select: {
      //         options: [
      //           {
      //             key: 1,
      //             value: '是'
      //           },
      //           {
      //             key: 2,
      //             value: '否'
      //           }
      //         ],
      //         multiple: false,
      //         filterable: true
      //       }
      //     }
      //   }
      // }
    ]
  }
}

export default Column
